//package com.leo.manage_system.base.handler;
//
//import com.leo.manage_system.utils.JwtUtils;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.boot.configurationprocessor.json.JSONObject;
//import org.springframework.stereotype.Component;
//
//import javax.servlet.*;
//import javax.servlet.http.HttpServletRequest;
//import java.io.IOException;
//import java.io.PrintWriter;
//import java.util.*;
//
///**
// * @Author: ywzjks
// * @Date: 2021/11/20 14:56
// * @Description:
// */
//@Component
//public class DoFilterHandler implements Filter {
//    JwtUtils jwtUtils = new JwtUtils();
//
////    @Override
////    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
////        filterChain.doFilter(servletRequest,servletResponse);
////
////    }
//    private static final Set<String> ALLOWED_PATHS = Collections.unmodifiableSet(new HashSet<>(
//            Arrays.asList("/swagger-ui.html", "/webjars/**")));
//    @Override
//    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
//        Map<String,String> map = new HashMap<>();
//        String url =  ((HttpServletRequest)servletRequest).getRequestURI();
//        System.out.println(url);
////
//////        filterChain.doFilter(servletRequest,servletResponse);
//////        return ;
//        if(url != null){
////            filterChain.doFilter(servletRequest,servletResponse);
////            boolean filterPath = url.contains(ALLOWED_PATHS);
////            System.out.println(filterPath);
//            //swagger请求直接放行
//            if (url.contains("swagger")||url.contains("api")){
//                filterChain.doFilter(servletRequest,servletResponse);
//                return ;
//            }
//            if(url.contains("/service_manage/admin/adminLogin")){
//
//                filterChain.doFilter(servletRequest,servletResponse);
//                return ;
//            }
//            else {
//                //其他请求验证token
//                String token = ((HttpServletRequest)servletRequest).getHeader("token");
////                String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJqdGkiOiIxNDYxMjI3OTEyMDQxNzc1MTA1IiwiZXhwIjoxNjM3NDg2ODQxLCJzdWIiOiIxMjMiLCJpYXQiOjE2Mzc0MDA0NDF9.QdD654iZ9H-UYK3t4f-dEFHS2NCEtthXl1HvNxr4TlA";
//                System.out.println(token);
////                filterChain.doFilter(servletRequest,servletResponse);
////                System.out.println("222222222");
//                if(StringUtils.isNotBlank(token)){
//                    //token验证结果
//                    int verify  = jwtUtils.verify(token);
//                    if(verify != 1){
//                        //验证失败
//                        if(verify == 2){
//                            map.put("errorMsg","token已过期");
//                        }else if(verify == 0){
//                            map.put("errorMsg","用户信息验证失败");
//                        }
//                    }else if(verify  == 1){
//                        //验证成功，放行
//                        filterChain.doFilter(servletRequest,servletResponse);
//                        return;
//                    }
//                }else{
//                    //token为空的返回
//                    map.put("errorMsg","未携带token信息");
//                }
//            }
//            JSONObject jsonObject = new JSONObject(map);
//            servletResponse.setContentType("application/json");
//            //设置响应的编码
//            servletResponse.setCharacterEncoding("utf-8");
//            //响应
//            PrintWriter pw=servletResponse.getWriter();
//            pw.write(jsonObject.toString());
//            pw.flush();
//            pw.close();
//        }
//
//        }
//
//
//}
